package com.schoolhelper.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import redis.clients.jedis.Jedis;


public class MyRedis {

    String host = "likeghee.ltd";
    String password = "as123456";
    Jedis jedis;

    public MyRedis() {
        //连接本地的 Redis 服务
        jedis = new Jedis(host);
        // 如果 Redis 服务设置了密码，需要下面这行，没有就不需要
        jedis.auth(password);
        System.out.println("redis连接成功, 服务正在运行: " + jedis.ping());
    }

    public void save(String key, String value) {
        jedis.set(key, value);
        System.out.println("redis save successfully");
    }

    public String get(String key) {
        System.out.println("redis 正在获取key数据 " + key);
        System.out.println(jedis.get(key));
        return jedis.get(key);

    }

    public void remove(String key){
        jedis.del(key);
    }
}
